#!/usr/bin/env python
# -*- coding: UTF-8 -*-
from flask import session, g


def signin_user(user, permenent):
    """Signin user"""
    session.permanent = permenent
    session['User'] = user


def signout_user():
    """Signout user"""
    session.pop('User', None)


def get_current_user():
    """获取当前user"""
    if 'User' not in session:
        return None
    if not g.user:
        signout_user()
        return None
    return g.user


class Singleton(object):
    _instances = {}

    def __new__(cls, *args, **kwargs):
        if cls not in cls._instances:
            cls._instances[cls] = super(Singleton, cls).__new__(cls, *args, **kwargs)
        return cls._instances[cls]
